﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Qreed.Windows.Forms;
using Qreed;
using Qreed.Windows;
using System.Diagnostics;

namespace ScopeTextBoxDemo
{
    public partial class TestForm : Form
    {
        public TestForm()
        {
            InitializeComponent();
            scopeTextBox1.RegularExpressionChanged += new EventHandler(scopeTextBox1_RegularExpressionChanged);
            scopeTextBox1.CreateScope += new EventHandler<Qreed.Windows.ScopeTextBoxEventArgs>(scopeTextBox1_CreateScope);
            scopeTextBox1.RemoveScope += new EventHandler<Qreed.Windows.ScopeTextBoxEventArgs>(scopeTextBox1_RemoveScope);
            scopeTextBox1.Text = "02 - A Perfect Circle - A title.mp3";

            _fields.Add("Artist", false);
            _fields.Add("Title", false);
            _fields.Add("Album", false);
            _fields.Add("Year", false);
            _fields.Add("Genre", false);
            _fields.Add("Track", false);
            _fields.Add("Comment", false);

            MenuToContextMenu contextMenu = new MenuToContextMenu(editToolStripMenuItem);
            reguTextBox.ContextMenuStrip = contextMenu;

            _intellisenseWindow.TextBox = textBox1;
            _intellisenseWindow.SenseKey = Keys.D5;
            _intellisenseWindow.SenseModifierKey = Keys.Shift;

            foreach (string k in _fields.Keys)
            {
                _intellisenseWindow.ListBox.Items.Add(k);
            }

            MessageSniffer msgSniffer = new MessageSniffer(true);

            msgSniffer.MessageReceived += new EventHandler<MessageSniffer.MessageEventArgs>(msgSniffer_MessageReceived);
            msgSniffer.TargetControl = scopeTextBox1;

            /*_intellisenseListBox = new IntellisenseListBox();
            _intellisenseListBox.TextBox = textBox1;
            _intellisenseListBox.IntellisenseInsert += new EventHandler<IntellisenseEventArgs>(_intellisenseListBox_IntellisenseInsert);
            Controls.Add(_intellisenseListBox);

            //_intellisenseListBox.SenseChar = '%';

            _intellisenseListBox.SenseKey = Keys.D5;
            _intellisenseListBox.SenseModifierKey = Keys.Shift;

            foreach (string k in _fields.Keys)
            {
                _intellisenseListBox.Items.Add(k);
            }*/
        }

        void msgSniffer_MessageReceived(object sender, MessageSniffer.MessageEventArgs e)
        {
            if (e.Message.Msg == (int)WindowMessage.MOUSEMOVE)
            {
                Debug.Write(e.Control);
                Debug.Write(" ");
                Debug.WriteLine((WindowMessage)e.Message.Msg);
            }
        }

        private IntellisenseWindow _intellisenseWindow = new IntellisenseWindow();
        
        private Dictionary<string, bool> _fields = new Dictionary<string, bool>();

        void scopeTextBox1_RemoveScope(object sender, Qreed.Windows.ScopeTextBoxEventArgs e)
        {
            _fields[e.Name] = false;
        }

        void scopeTextBox1_CreateScope(object sender, Qreed.Windows.ScopeTextBoxEventArgs e)
        {
            SelectFieldDialog dlg = new SelectFieldDialog(_fields);

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                _fields[dlg.SelectedField] = true;
                e.Name = dlg.SelectedField;
            }
            else
                e.Cancel = true;
        }

        void scopeTextBox1_RegularExpressionChanged(object sender, EventArgs e)
        {
            reguTextBox.Text = scopeTextBox1.RegularExpression;
        }

        private void cloneToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Click");
        }
    }
}
